package com.test.zk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ServiceProxy {
    private Object target;

    public ServiceProxy(Object target) {
        super();
        this.target = target;
    }

    public Object getProxyInstance() {
        Class clazz = target.getClass();//使用反射
        return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("service执行了");
                // 执行目标对象方法
                Object returnValue = method.invoke(target, args);
                System.out.println("对象方法执行完了");
                return returnValue;
            }
        });
    }
}
